package huzh.foundation.action;

import java.util.Enumeration;

import javax.servlet.http.HttpServletRequest;

/**
 *<p>title:BaseVOOperation</p>
 *<p>description:</p>
 * @since 2014-6-21
 * @author huzh
 * @version 1.0
 */
public class BaseVOOperation {

    /**
     * @return
     */
    public static BaseVO transRequestToBaseVO(HttpServletRequest request){
        BaseVO vo = new BaseVO();
        vo = transRequestToBaseVO(request, vo);
        return vo;
    }
    
    /**
     * @param request
     * @param vo
     * @return
     */
    @SuppressWarnings("unchecked")
    public static BaseVO transRequestToBaseVO(HttpServletRequest request, BaseVO vo){
        Enumeration e =request.getParameterNames();
        String eleName = null;
        while(e.hasMoreElements()) {
            eleName = e.nextElement().toString();
            vo.setRequestObject(eleName, request.getParameter(eleName));
        }
        
        Enumeration e2 =request.getAttributeNames();
        while(e2.hasMoreElements()) {
            eleName = e2.nextElement().toString();
            vo.setRequestObject(eleName, request.getAttribute(eleName));
        }
        vo.setRequestObject("remoteAddr", request.getRemoteAddr());
        vo.setRequestObject("requestURI", request.getRequestURI());
        vo.setRequestObject("queryString", request.getQueryString());
        vo.setRequestObject("localAddr", request.getLocalAddr());
        vo.setRequestObject("localName", request.getLocalName());
        return vo;
    }
}
